/*
 * GravarContatoAction.java
 *
 * Created on 18 de Novembro de 2006, 12:38
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package action;

import controller.Action;
import java.io.IOException;
import javax.servlet.http.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Exercicio;
import percistence.ExercicioDAO;

public class GravarExercicioAction implements Action {
    
    public GravarExercicioAction() {
    }
    
    public void execute(HttpServletRequest request,
            HttpServletResponse response ) throws IOException {
        String serie = request.getParameter("textSerie");
        String repeticao = request.getParameter("textRepeticao");
        String idTipoExercicio = request.getParameter("textIdTipoExercicio");
        
        Exercicio exercicio = new Exercicio();
        exercicio.setSerie(serie);
        exercicio.setRepeticao(repeticao);
        //Falta relacionar o Exercicio com seu tipo
        //exercicio.setTipoExercicio();;
        
        if("".equals(exercicio.getSerie())) {
            response.sendRedirect("index.jsp");
        } else {
            try {
                ExercicioDAO.getInstance().salvar(exercicio);
                response.sendRedirect("index.jsp");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(GravarExercicioAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
